package com.mjk.common.core.jdbc.sphere.impl.database;

import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class ShardingDatabaseAlgorithm implements ComplexKeysShardingAlgorithm<String> {
    private final String sharding;

    public ShardingDatabaseAlgorithm(String dataSource) {
        this.sharding = dataSource;
    }


    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames,ComplexKeysShardingValue<String> shardingValue) {
        return new ArrayList<>(Arrays.asList(sharding.split(",")));
    }
}
